#include <stdio.h>
#include <gtk/gtk.h>

int main(int agrc, char* argv[])
{
    gtk_init(&agrc, &argv);
    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Gtk Demo");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);

    // Create a menu bar: file, edit, view
    GtkWidget* menubar = gtk_menu_bar_new();
    GtkWidget* filemenu = gtk_menu_new();
    GtkWidget* editmenu = gtk_menu_new();
    GtkWidget* viewmenu = gtk_menu_new();
    GtkWidget* file = gtk_menu_item_new_with_label("File");
    GtkWidget* edit = gtk_menu_item_new_with_label("Edit");
    GtkWidget* view = gtk_menu_item_new_with_label("View");

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(edit), editmenu);
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), viewmenu);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), edit);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), view);

    printf("file: %p, parent: %p\n", file, gtk_widget_get_parent(file));
    printf("edit: %p, parent: %p\n", edit, gtk_widget_get_parent(edit));
    printf("view: %p, parent: %p\n", view, gtk_widget_get_parent(view));

    // Create a menu item: new, open, save, quit
    GtkWidget* new = gtk_menu_item_new_with_label("New");
    GtkWidget* open = gtk_menu_item_new_with_label("Open");
    GtkWidget* save = gtk_menu_item_new_with_label("Save");
    GtkWidget* quit = gtk_menu_item_new_with_label("Quit");

    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), new);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);

    GtkWidget* configure = gtk_menu_item_new_with_label("Configure");
    GtkWidget* preferences = gtk_menu_item_new_with_label("Preferences");
    gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), configure);
    gtk_menu_shell_append(GTK_MENU_SHELL(editmenu), preferences);

    GtkWidget* maximize = gtk_menu_item_new_with_label("Maximize");
    GtkWidget* minimize = gtk_menu_item_new_with_label("Minimize");
    gtk_menu_shell_append(GTK_MENU_SHELL(viewmenu), maximize);
    gtk_menu_shell_append(GTK_MENU_SHELL(viewmenu), minimize);

    // Create a vbox
    GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    // Add menubar to vbox
    gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);

    // Create a text view
    // GtkWidget* textview = gtk_text_view_new();
    // gtk_box_pack_start(GTK_BOX(vbox), textview, TRUE, TRUE, 0);

    // Show all widgets
    gtk_widget_show_all(window);

    gtk_main();
    return 0;
}